package xin.controller;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import xin.anotation.Permissions;
import xin.entity.CommonResult;
import xin.entity.TOrgDepartment;
import xin.service.TOrgDepartmentService;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author young
 * @since 2023年10月09日
 */
@RestController
@RequestMapping("/tOrgDepartment")
@Permissions(name = "部门权限",sn = "Department:")
public class TOrgDepartmentController {

    @Resource
    private TOrgDepartmentService departmentService;


    @GetMapping("/findAll")
    @Permissions(name = "查询所有部门信息",sn = "Department:findAll")
    public CommonResult<?> findAll(Integer page, Integer size,String keyWorld){
        return CommonResult.success(this.departmentService.findAll(keyWorld,page,size),"查询成功");
    }
    @PostMapping("/add")
    @Permissions(name = "添加部门信息",sn = "Department:add")
    public CommonResult<?> add(@RequestBody TOrgDepartment department){
        return this.departmentService.add(department)>0?CommonResult.success(null,"添加成功"):CommonResult.error(499,"网络异常");
    }
    @PostMapping("/deleteBatch")
    @Permissions(name = "批量删除部门信息",sn = "Department:deleteBatch")
    public CommonResult<?> deleteBatch(@RequestBody List<Long> ids){
        return this.departmentService.delete(ids)>0?CommonResult.success(null,"删除成功"):CommonResult.error(499,"网络异常");
    }

    @GetMapping("/findById/{id}")
    @Permissions(name = "根据id查询部门信息",sn = "Department:findById")
    public CommonResult<?> findById(@PathVariable("id")Long id){
        return CommonResult.success(this.departmentService.findById(id),"请求成功");
    }
    @PutMapping("/update")
    @Permissions(name = "更新部门信息",sn = "Department:update")
    public CommonResult<?> update(@RequestBody TOrgDepartment department){
        return
        this.departmentService.update(department)>0?CommonResult.success(null,"修改成功"):CommonResult.error(499,"网络异常");
    }


}

